package cn.mall.base.utils;

import cn.mall.org.domain.Manager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;


/**
 * @Auther:Jarvis
 * @Date:2023年03月2023/3/15日09:40
 * @Description:登录上下文，获取当前登录人的信息，存入全局map
 */
@Component
public class LoginContext {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 存放登录信息
     */
    public static void setLoginUser(Manager loginUser) {

    }

    /**
     * 获取登录信息
     */
    public Manager getLoginUser(HttpServletRequest request) {
        String token = request.getHeader("token");
        if (StringUtils.isEmpty(token)) {
            return null;
        } else {
            Object loginUser = redisTemplate.opsForValue().get(token);
            return (Manager) loginUser;
        }

    }

}
